<?php
/**
 * Created by PhpStorm.
 * User: spring
 * Date: 2022/1/12
 * Time: 16:53
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Clin extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model(array('clin_xunzheng' => 'xunzheng'));
    }

    public function index($page=1){
        if(!$page || $page == 'false'){ // 查找第一条数据
            $page = 1;

        }
        sleep(2);
        $url = 'http://clinicalcore.cn/zskapi/api/search/xzwxList';
        $data['keywords'] = '';
        $data['page'] = $page;
        $data['pageSize'] = 100;
        $data['tyv'] = '全部';
        $proxy_info = json_decode('{"proxy":"110.90.223.147:23015","userpwd":"9492705:a9ggjqzs"}', true);
        $file = http_post($url,http_build_query($data),$proxy_info);
        var_dump($file);exit;
        $file = $this->removeBOM($file);
        $infos = json_decode(trim($file),true);
        $data = $infos['list'];
        if(empty($data)){
            echo "nodata";
            exit;
        }
        foreach($data as $vo){
            $ins = $vo;
            //if(!$this->data->get_by_where("classen='{$en}' and id='{$vo['id']}'")){
            //var_dump($ins);exit;
            $this->xunzheng->insert($ins);
            //}
        }
        echo $page+1;
    }
    function removeBOM($data) {
        if (0 === strpos(bin2hex($data), 'efbbbf')) {
            return substr($data, 3);
        }
        return $data;
    }

    public function file(){
        $url = 'http://clinicalcore.cn/zskapi/api/Search/getFile?token=igm49P%mmd2F%mmd2BnD5WIziSX3f6ExAg9iEsjTW8S%mmd2FrNKPzdeqk=&filename=XDKF202123028&t=11&year=2021';
        $proxy_info = json_decode('{"proxy":"114.231.42.131:20966","userpwd":"9492705:a9ggjqzs"}', true);
        $file = http_get($url);
        echo $file;
    }
}